﻿//button抽象控件，需要tools.js、proto.js模块

if (!window.wkh.classes) {
    window.wkh.classes = {
        controls: {}
    };
}

if(!window.wkh.classes.controls){
    window.wkh.classes.controls = {};
}

window.wkh.classes.controls.Control = (function () {
    var controlNum = 0;
    var allControls = [];
    var allDivs = [];

    var pri;
    function classControl(div,width,height,name,style) {
        if (this.className === "Control") {
            throw new SyntaxError("This is a abstract class.");
        } else {
            if (div.tagName && div.tagName === "DIV") {
                div.innerHTML = "";
                div.style.cssText = "";
            } else {
                throw new TypeError("使用Div元素做为容器");
            }

            if (allDivs.contains(div) === -1) {
                allControls.push(this);
                allDivs.push(div);

                ++controlNum;
            }

            div.getClassList().add("__wkh_private_Control");
            width = width || "";
            height = height || "";

            var privateVar = {
                name: name || ("Control"),
                element: div,
                width: width,
                height: height,
                style: style || null
            };
            div.css({ width: width, height: height,overflow:"hidden",padding:"0",margin:"0",border:"0px none white" });
            div.css(style);


            this.__wkh_private_getControlPrivate = function () {
                pri = privateVar;
            };
        }
    }

    classControl.prototype.setWidth = function (width) {
        this.__wkh_private_getControlPrivate();
        pri.width = width;
        pri.element.css("width", width);
    };
    classControl.prototype.setHeight = function (height) {
        this.__wkh_private_getControlPrivate();
        pri.height = height;
        pri.element.css("height", height);
    };
    classControl.prototype.remove = function () {
        this.__wkh_private_getControlPrivate();

        allDivs.remove(allDivs.contins(pri.element));
        allControls.remove(allControls.contains(this));

        pri.element.parentNode.removeChild(pri.element);
        pri.element = null;
        --controlNum;
    };
    classControl.prototype.getControlName = function () {
        this.__wkh_private_getControlPrivate();
        return pri.name;
    };

    classControl.prototype.className = "Control";

    classControl.getNum = function () {
        return controlNum;
    };
    classControl.__wkh_private_className = "Control";

    return classControl;
}());